#include "sdl_game_object.h"
#include "texture_manager.h"
#include "game.h"

// 调用父类的构造函数
SDLGameObject::SDLGameObject() : GameObject() { }

Vector2D& SDLGameObject::get_position() {
    return position_;
}

int SDLGameObject::get_width() const {
    return width_;
}

int SDLGameObject::get_height() const {
    return height_;
}

void SDLGameObject::Draw() {
    if (velocity_.getx() < 0) {
        TheTM::instance().DrawFrame(textureid_, (Uint32)position_.getx(), (Uint32)position_.gety(),
                              width_, height_, current_row_, current_frame_,
                              TheGame::instance().get_renderer(), SDL_FLIP_HORIZONTAL);
    }
    else {
        TheTM::instance().DrawFrame(textureid_, (Uint32)position_.getx(), (Uint32)position_.gety(),
                              width_, height_, current_row_, current_frame_,
                              TheGame::instance().get_renderer());
    }
}

void SDLGameObject::Update() {
    velocity_ += acceleration_;
    position_ += velocity_;
}

void SDLGameObject::Clean() {

}

void SDLGameObject::Load(const LoadParams* params) {
    position_ = Vector2D(params->get_x(), params->get_y());
    velocity_ = Vector2D(0.0f, 0.0f);
    acceleration_ = Vector2D(0.0f, 0.0f);
    width_ = params->get_width();
    height_ = params->get_height();
    textureid_ = params->get_textureid();
    current_row_ = 1;
    current_frame_ = 1;
    num_frames_ = params->get_numframes();
    anim_speed_ = params->get_anim_speed();
}
